package com.xuan.commons.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


import java.util.ArrayList;
import java.util.List;

/**
 * @author renzhengxuan
 * @date 2021/5/16
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket sysDocket(){
        return docket("系统用户","com.xuan.modules.system");
    }
    @Bean
    public Docket authDocket(){
        return docket("认证授权","com.xuan.modules.auth");
    }


    private Docket docket(String groupName,String basePage){
        return new Docket(DocumentationType.SWAGGER_2)

                .apiInfo(apiInfo())
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePage))
                //只有加了@ApiOperation这个注解才可以生成swagger
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("后台Api文档")
                .description("api")
                .version("V1.0")
                .build();
    }
}
